package cn.itcast.bos.service.base.impl;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.base.PromotionDao;
import cn.itcast.bos.domain.page.PageBean;
import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.bos.service.base.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {
	// 注入dao
	@Autowired
	private PromotionDao pd;

	@Override
	public void save(Promotion model) {
		pd.save(model);
	}

	@Override
	public Page<Promotion> findPageData(Pageable pageable) {
		Page<Promotion> page = pd.findAll(pageable);
		return page;
	}

	@Override
	public PageBean<Promotion> findPageData(int page, int rows) {
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> pageData = pd.findAll(pageable);
		//封装对象
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setTotalCount(pageData.getTotalElements());
		pageBean.setPageData(pageData.getContent());
		return pageBean;
	}


}
